package com.powernode.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.powernode.domain.Category;
import com.powernode.domain.Prod;
import com.powernode.domain.ProdProp;
import com.powernode.service.ProdPropService;
import com.powernode.service.ProdService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 *
 */
@RequestMapping("prod/spec")
@RestController
@Api(tags = "产品规格管理接口")
public class ProdPropController {

    @Autowired
    private ProdPropService prodPropService;

    @GetMapping("/page")
    @PreAuthorize("hasAuthority('prod:spec:page')")
    @ApiOperation("规格管理")
    public ResponseEntity<Page<ProdProp>> getProdPropPage(Page<ProdProp> page, ProdProp prodProp) {
        page = prodPropService.getProdPropPage(page, prodProp);
        return ResponseEntity.ok(page);
    }


    @GetMapping("/list")
    @PreAuthorize("hasAuthority('prod:spec:page')")
    @ApiOperation("规格列表")
    public ResponseEntity<List<ProdProp>> getListProdProp() {
        List<ProdProp> list = prodPropService.list();
        return ResponseEntity.ok(list);
    }

    @PostMapping
    @PreAuthorize("hasAuthority('prod:spec:save')")
    @ApiOperation("新增规格")
    public ResponseEntity<Void> addProdPropValue(@RequestBody ProdProp prodProp) {
        prodPropService.addProdPropValue(prodProp);
        return ResponseEntity.ok().build();
    }
}
